using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
using System; //it is needed for Serializable

namespace SharedLibrary
{
    class CommonStruct
    {
        [Serializable]
        public enum MouseButtonState
        {
            None = 0,
            ButtonClick,
            ButtonPressed,
            DblClick
        }

        [Serializable]
        public enum WorkMode
        {
            TouchPad = 0,
            TouchScreen
        } ;

        [Serializable]
        public struct TouchPro
        {
            public Point point;
            public MouseButtonState buttonState;
            public WorkMode mode;
            public Size currSize;
            public int Sequence;
         //   public bool buttonDblClick;
            // public bool buttonClick;
        }         
    }
    class CommonConvertion
    {
        public static byte[] StructureToByteArray(object obj)
        {
            int Length = Marshal.SizeOf(obj);
            byte[] bytearray = new byte[Length];
            IntPtr ptr = Marshal.AllocHGlobal(Length);
            Marshal.StructureToPtr(obj, ptr, false);
            Marshal.Copy(ptr, bytearray, 0, Length);
            Marshal.FreeHGlobal(ptr);
            return bytearray;
        }

        public static void ByteArrayToStructure(byte[] bytearray, ref object obj)
        {
            int Length = Marshal.SizeOf(obj);
            IntPtr ptr = Marshal.AllocHGlobal(Length);
            Marshal.Copy(bytearray, 0, ptr, Length);
            obj = Marshal.PtrToStructure(ptr, obj.GetType());
            Marshal.FreeHGlobal(ptr);
        }
    }
}
